import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-11-04
 * Time: 17:34
 */
public class Demo2 {
    public static void main(String[] args) {
        //创建线程池
        ExecutorService threadPool = new ThreadPoolExecutor(
                3,//核心线程数
                5,//最大线程数
                60,//空闲时间
                TimeUnit.SECONDS,//单位秒
                new ArrayBlockingQueue<>(100),//容量为10的阻塞队列
                Executors.defaultThreadFactory(),//默认线程工厂类
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略：抛出异常
        );
        for (int i = 0; i < 100; i++) {
            int id = i;
            threadPool.submit(() -> {
                System.out.println(Thread.currentThread().getName() + ": " + id);
            });
        }
        threadPool.shutdown();
    }
}
